﻿/*
 * ========================================================================
 * Copyright(c) 2008-2010北京高阳金信信息技术有限公司, All Rights Reserved.
 * ========================================================================
 *  基金行情业务类
 * 
 * 作者：邓太华     时间：2010-06-04至08
 * 版本：V1.0
 * 
 * 修改者： 马德强        时间： 2010-06-22               
 * 修改说明：增加基金行情相关算法
 * ========================================================================
*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NBFModel;
using NBFDAL.SqlMapDAL;
using PWMIS.DataMap.Entity; 

namespace NBFBLL
{
    /// <summary>
    /// 基金行情类
    /// </summary>
   public  class FundMarket
    {
       /// <summary>
       /// 获取所有基金行情信息
       /// </summary>
       /// <returns></returns>
       public List<Model_FoundMarket> GetFundMarket()
       {
           FundMarketDAL dal = new FundMarketDAL();
           List<Model_FoundMarket> list=dal.GetFoundMarket();
           //if (list.Count > 4)
           //{
           //    Model_FoundMarket m = list[4];
           //    decimal d = m.month6yield;
           //}
           return list;
       }

       /// <summary>
       /// 获取基金申购状态
       /// </summary>
       /// <param name="jjdm">基金系统代码</param>
       /// <returns></returns>
       public List<Model_FoundMarket> GetFundBuyState(string jjdm)
       {
           FundMarketDAL dal = new FundMarketDAL();
           return dal.GetFundBuyState(jjdm);
       }


       /// <summary>
       /// 获取基金公司
       /// </summary>
       /// <returns></returns>
       public List<Model_FundCompany> GetFundCompany(string jjdm)
       {
           FundMarketDAL dal = new FundMarketDAL();
           return dal.GetFundCompany(jjdm);
       }

       /// <summary>
       /// 获取同公司基金
       /// </summary>
       /// <param name="jjdm">基金系统代码</param>
       /// <returns></returns>
       public List<Model_FoundMarket> GetFundOfCompany(string jjdm)
       {
           FundMarketDAL dal = new FundMarketDAL();
           return dal.GetFundOfCompany(jjdm);
       }

       /// <summary>
       /// 获取基金公告
       /// </summary>
       /// <param name="jjdm">系统基金代码</param>
       /// <returns></returns>
       public List<Model_Announcement> GetFundAnnouncemen(string jjdm)
       {
           FundMarketDAL dal = new FundMarketDAL();
           return dal.GetFundAnnouncement(jjdm);
       }

       /// <summary>
       /// 获取基金新闻
       /// </summary>
       /// <param name="jjdm">系统基金代码</param>
       /// <returns></returns>
       public List<Model_News> GetFundNews(string jjdm)
       {
           FundMarketDAL dal = new FundMarketDAL();
           return dal.GetFundNews(jjdm);
       }

       /// <summary>
       /// 获取基金概况
       /// </summary>
       /// <param name="jjdm">系统基金代码</param>
       /// <returns></returns>
       public List<Model_Overview> GetFundOverview(string jjdm)
       {
           FundMarketDAL dal = new FundMarketDAL();
           List<Model_Overview> list = dal.GetFundOverview(jjdm);
           string str="";
           string[] strs;

           string [] splits=new string[8];
           splits[0] = "投资目标：";
           splits[1] = "投资方向：";
           splits[2] = "投资理念：";
           splits[3] = "投资策略：";
           splits[4] = "投资基准：";
           splits[5] = "选股基准：";
           splits[6] = "业绩比较基准：";
           splits[7] = "风险收益特征：";
           bool[] flags = new bool[8];
           int[] strLocation = new int[8];
           
           for (int i = 0; i < list.Count; i++)
           {
               str = list[i].TzSM;
               for (int j = 0; j < splits.Length; j++)
               {
                   #region - 备份代码 -
                   //if (str.IndexOf(splits[j]) > -1)
                   //{
                   //    flags[j] = true;
                   //    strLocation[j] = str.IndexOf(splits[j]);
                   //} 
                   #endregion
                   str = str.Replace(splits[j], "|");
               }

           }
           strs = str.Split('|');
           list[0].投资目标 = strs[1];
           list[0].投资方向 = strs[2];
           list[0].投资理念 = strs[3];
           list[0].投资策略 = strs[4];
           list[0].投资基准 = strs[5];
           list[0].选股基准 = strs[6];
           list[0].业绩比较基准 = strs[7];
           list[0].风险收益特征 = strs[8];
           #region - 备份代码 -
           //if (flags[0])
           //{
           //    list[0].投资目标 = str.Substring(strLocation[0],str.Substring(0,strLocation[1]).Length);
           //}
           //if (flags[1])
           //{
           //    list[0].投资方向 = str.Substring(strLocation[1], str.Substring(strLocation[1], strLocation[2]).Length);
           //}
           //if (flags[2])
           //{
           //    list[0].投资理念 = str.Substring(strLocation[2], str.Substring(strLocation[2], strLocation[3]).Length);
           //}
           //if (flags[3])
           //{
           //    list[0].投资策略 = str.Substring(strLocation[3], str.Substring(strLocation[3], strLocation[4]).Length);
           //}
           //if (flags[4])
           //{
           //    list[0].投资基准 = str.Substring(strLocation[4], str.Substring(strLocation[4], strLocation[5]).Length);
           //}
           //if (flags[5])
           //{
           //    list[0].选股基准 = str.Substring(strLocation[5], str.Substring(strLocation[5], strLocation[6]).Length);
           //}
           //if (flags[6])
           //{
           //    list[0].业绩比较基准 = str.Substring(strLocation[6], str.Substring(strLocation[6], strLocation[7]).Length);
           //}
           //if (flags[7])
           //{
           //    list[0].风险收益特征 = str.Substring(strLocation[7]);
           //} 
           #endregion
           return list;
       }

       /// <summary>
       /// 获取基金拆分
       /// </summary>
       /// <param name="jjdm">系统基金代码</param>
       /// <returns></returns>
       public List<Model_Split> GetFundSplit(string jjdm)
       {
           FundMarketDAL dal = new FundMarketDAL();
           return dal.GetFundSplit(jjdm);
       }

       /// <summary>
       /// 获取基金分红
       /// </summary>
       /// <param name="jjdm">系统基金代码</param>
       /// <returns></returns>
       public List<Model_Dividend> GetFundDividend(string jjdm)
       {
           FundMarketDAL dal = new FundMarketDAL();
           return dal.GetFundDividend(jjdm);
       }

       /// <summary>
       /// 获取基金净值数据绑定到K图用
       /// </summary>
       /// <param name="jjdm">系统基金代码</param>
       /// <returns></returns>
       public List<FundDetailsInfo> GetFundDetailsInfo(string jjdm)
       {
           FundMarketDAL dal = new FundMarketDAL();
           return dal.GetFundDetailsInfo(jjdm);
       }

       /// <summary>
       /// 获取基金经理信息
       /// </summary>
       /// <param name="jjdm">系统基金代码</param>
       /// <returns></returns>
       public List<Model_FundManager> GetFundManager(string jjdm)
       {
           FundMarketDAL dal = new FundMarketDAL();
           return dal.GetFundManager(jjdm);
       }

       /// <summary>
       /// 获取申购赎回信息
       /// </summary>
       /// <param name="jjdm">系统基金代码</param>
       /// <returns></returns>
       public List<Model_BuyAndSale> GetFundBuyAndSale(string jjdm)
       {
           FundMarketDAL dal = new FundMarketDAL();
           return dal.GetFundBuyAndSale(jjdm);
       }

       /// <summary>
       /// 获取基金行业配置
       /// </summary>
       /// <param name="jjdm">系统基金代码</param>
       /// <returns></returns>
       public List<Model_IndustryConfig> GetFundIndustryConfig(string jjdm)
       {
           FundMarketDAL dal = new FundMarketDAL();
           return dal.GetFundIndustryConfig(jjdm);
       }

       /// <summary>
       /// 获取基金重仓持股信息
       /// </summary>
       /// <param name="jjdm"></param>
       /// <returns></returns>
       public List<Model_FundHoldStock> GetFundHoldStock(string jjdm)
       {
           FundMarketDAL dal = new FundMarketDAL();
           return dal.GetFundHoldStock(jjdm);
       }

       /// <summary>
       /// 获取基金交叉持股信息
       /// </summary>
       /// <param name="jjdm"></param>
       /// <returns></returns>
       public List<Model_FundCrossStock> GetFundCrossStock(string jjdm)
       {
           FundMarketDAL dal = new FundMarketDAL();
           return dal.GetFundCrossStock(jjdm);
       }

       /// <summary>
       /// 获取基金规模
       /// </summary>
       /// <param name="jjdm"></param>
       /// <returns></returns>
       public List<Model_FundScale> GetFundScale(string jjdm)
       {
           FundMarketDAL dal = new FundMarketDAL();
           return dal.GetFundScale(jjdm);
       }
       
       /// <summary>
       /// 获取同期发行基金
       /// </summary>
       /// <param name="jjdm"></param>
       /// <returns></returns>
       public List<Model_FundSamilerDate> GetFundSamilerDate(string jjdm)
       {
           FundMarketDAL dal = new FundMarketDAL();
           return dal.GetFundSamilerDate(jjdm);
       }

       /// <summary>
       /// 获取同基金公司的基金
       /// </summary>
       /// <param name="jjdm"></param>
       /// <returns></returns>
       public List<Model_FundSamilerCompany> GetFundSamilerCompany(string jjdm)
       {
           FundMarketDAL dal = new FundMarketDAL();
           return dal.GetFundSamilerCompany(jjdm);
       }

       /// <summary>
       /// 获取基金净值列表
       /// </summary>
       /// <param name="jjdm"></param>
       /// <returns></returns>
       public List<Model_FundDWJZList> GetFundDWJZList(string jjdm)
       {
           FundMarketDAL dal = new FundMarketDAL();
           List<NBFModel.Model_FundDWJZList> list = dal.GetFundDWJZList(jjdm);
           for (int i = 1; i < list.Count; i++)
           {
               if (i == list.Count - 1)
               {
                   list[i].日涨跌 = 0;
                   list[i].日涨幅 = 0;
               }
               list[i - 1].日涨跌 = list[i - 1].累计净值 - list[i].累计净值;
               list[i - 1].日涨幅 = list[i - 1].日涨跌 / list[i].累计净值 * 100;
           }
           return list;
       }

       /// <summary>
       /// 获取同类型基金信息
       /// </summary>
       /// <param name="jjdm"></param>
       /// <returns></returns>
       public List<Model_FundSamilerType> GetFundSamilerType(string jjdm)
       {
           FundMarketDAL dal = new FundMarketDAL();
           return dal.GetFundSamilerType(jjdm);
       }
    }
}
